

import ProgressBarCom from "../component/ProgressBarCom"
import EventName from "./EventName";
import UserData from "./UserData";
const { ccclass, property } = cc._decorator;

@ccclass
export default class InfoPanelItem extends cc.Component {

    @property(ProgressBarCom)
    progressBarCom: ProgressBarCom = null;

    @property(cc.Node)
    warn: cc.Node = null;

    @property(cc.String)
    infoType = ""

    start() {
        cc.director.getScene().on(EventName.UPDATE_GAME_CONTENT, this.initData, this);
    }

    get progress() {
        if (UserData.getInstance().birthData) {
            return UserData.getInstance().birthData[this.infoType]
        } else {
            return 0;
        }
    }

    initData() {
        this.progressBarCom.init(this.progress);
        this.updateUI();
    }

    updateUI() {

        //是否显示危险
        if (this.progress < 0.05) {
            this.warn.opacity = 255;
        } else {
            this.warn.opacity = 0;
        }
    }

}
